#!/usr/bash

VERSION="$1"

if [ "$VERSION" == '' ]; then
	echo 'You must provide a release number'
	
	exit
fi

TAGDIR='./tags/'$VERSION

# tag off the release if it hasn't been tagged yet
if test -d "$TAGDIR" -eq false; then
	svn copy trunk/* $TAGDIR

	svn ci $TAGDIR -m "Create $VERSION tag."
fi

#create the temporary directory
mkdir ./__temp

# export the newly created tag to the temporary directory
svn export $TAGDIR'/lib' './__temp/EuropaPHP_'$VERSION'_Core' --force
svn export $TAGDIR       './__temp/EuropaPHP_'$VERSION'_Sandbox' --force

# move into the temporary directory
cd ./__temp/

# zip up the core
zip -r '../EuropaPHP_'$VERSION'_Core.zip' './EuropaPHP_'$VERSION'_Core'

# zip up the sandbox
zip -r '../EuropaPHP_'$VERSION'_Sandbox.zip' './EuropaPHP_'$VERSION'_Sandbox'
zip -r '../EuropaPHP_'$VERSION'_Sandbox.zip' -i .htaccess

# create a EuropaPHP Ultra file and zip it up
cd ..
mkdir './__temp/EuropaPHP_'$VERSION'_Ultra'
/usr/bin/php -r 'require_once "./Europa_Ultra.php"; $ultra = new Europa_Ultra("'$VERSION'"); $ultra->save("./__temp/EuropaPHP_'$VERSION'_Ultra/Europa.php");'
cd ./__temp
zip -r '../EuropaPHP_'$VERSION'_Ultra.zip' './EuropaPHP_'$VERSION'_Ultra'

# move out of the temporary directory
cd ..

# remove the temporary directory
rm -rf ./__temp